<template>
	<div class="container">
		<div class="name">
			<span>联系人：</span>
			<input placeholder="请填写收货人的姓名" auto-focus v-model="name" />
		</div>
		<!-- <div class="sex">
      <i-panel title="group-水果">
        <i-radio-group current="current" bindchange="handleFruitChange">
          <i-radio v-for="(item,index) in fruit" :key="index" position="position" value="item.name">
          </i-radio>
        </i-radio-group>
      </i-panel>
    </div> -->
		<div class="phone">
			<span>手机号：</span>
			<input placeholder="请填写收货人手机号码" auto-focus v-model="phone" />
		</div>
		<div class="address">
			<span class="l">收货地址：</span>
			<div class="m" @click="goCity()">
				<i class="icon mt-location-o"></i>
				<span v-if="address=='' ">选择地址</span>
				<span else>{{address}}</span>
			</div>
			<div class="r">
				<i class="icon mt-arrow-right-o"></i>
			</div>
		</div>
		<div class="house-num">
			<span>门牌号：</span>
			<input placeholder="详细地址，例：16号楼5楼301室" auto-focus v-model="detailAdress" />
		</div>
		<div class="submit" @click="submit">
			<span>保存地址</span>
		</div>
		<div class="submit1" @click="deleteAddress">
			<span>删除地址</span>
		</div>
	</div>
</template>

<script>
import {RegExpr} from '@/utils/regex'
import {request} from '@/wxRequest/requestApi'
export default {
	data() {
		return {
			name: '',
			phone: '',
			detailAdress: '',
			id: '',
			address: '',
			jingdu: '',
			weidu: '',
		}
	},
	methods: {
		//删除地址
		//删除地址
		deleteAddress() {
			var that = this
			let getParams = {
				url: '/miniprogramOrder/updateIsActived',
				data: {
					id: this.id,
				},
				method: 'POST',
			}
			request(getParams).then(re => {
				wx.showToast({
					title: '删除成功',
					icon: 'success',
					duration: 2000,
					success() {
						wx.navigateTo({url: '/pages/addressList/main'})
					},
				})
			})
		},
		//提交地址信息
		submit() {
			let that = this
			if (that.name == '') {
				return false
			}
			if (RegExpr.checkNum(that.phone)) {
			} else {
			}
			if (that.phone == '') {
				return false
			}
			if (that.address == '') {
				return false
			}
			if (that.detailAdress == '') {
				return false
			}
			let getParams = {
				url: '/miniprogramOrder/updateMemAddress',
				data: {
					address: that.address,
					detailed: that.detailAdress,
					addressee: that.name,
					phone: that.phone,
					isDefault: 0,
					userId: wx.getStorageSync('userId'),
					isdell: 1,
					id: that.id,
				},
				method: 'POST',
			}
			request(getParams).then(re => {
				wx.showToast({
					title: '提交成功',
					icon: 'success',
					duration: 2000,
					success() {
						wx.navigateTo({url: '/pages/addressList/main'})
					},
				})
			})
		},
		goCity() {
			wx.navigateTo({url: '/pages/selectCity/main?id=1'})
		},
	},

	onLoad(options) {
		if (options.addressGo) {
			this.address = options.addressGo
			// this.jingdu=options.jingdu
			// this.weidu=options.weidu
		} else {
		}
		if (options.detailAdress || options.dizhi || options.name || options.phone) {
			this.name = options.name
			this.phone = options.phone
			this.detailAdress = options.detailAdress
			this.address = options.dizhi
			this.id = options.id
		} else {
		}
	},
}
</script>

<style lang="scss" scoped>
.container {
	background-color: white;
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	.name {
		display: flex;
		align-items: center;
		margin-left: 30rpx;
		padding-right: 30rpx;
		height: 88rpx;
		border-bottom: 2rpx solid $spLine-color;
		span {
			font-size: 28rpx;
			color: $textBlack-color;
			width: 160rpx;
		}
		input {
			flex: 1;
			font-size: 25rpx;
		}
	}
	.sex {
		display: flex;
		align-items: center;
		margin-left: 30rpx;
		padding-right: 30rpx;
		height: 88rpx;
		border-bottom: 2rpx solid $spLine-color;
		.l {
			width: 160rpx;
		}
		.m {
			display: flex;
			i {
				font-size: 32rpx;
				color: $theme-color;
			}
			span {
				font-size: 28rpx;
				color: $textBlack-color;
				margin-left: 20rpx;
			}
		}
		.r {
			display: flex;
			margin-left: 60rpx;
			i {
				font-size: 38rpx;
				color: $textGray-color;
			}
			span {
				font-size: 28rpx;
				color: $textBlack-color;
				margin-left: 20rpx;
			}
		}
	}
	.phone {
		display: flex;
		align-items: center;
		margin-left: 30rpx;
		padding-right: 30rpx;
		height: 88rpx;
		border-bottom: 2rpx solid $spLine-color;
		span {
			font-size: 28rpx;
			color: $textBlack-color;
			width: 160rpx;
		}
		input {
			flex: 1;
			font-size: 25rpx;
		}
	}
	.address {
		display: flex;
		align-items: center;
		margin-left: 30rpx;
		padding-right: 30rpx;
		height: 88rpx;
		border-bottom: 2rpx solid $spLine-color;
		.l {
			font-size: 28rpx;
			color: $textBlack-color;
			width: 160rpx;
		}
		.m {
			display: flex;
			flex: 1;
			i {
				font-size: 38rpx;
				color: $textGray-color;
			}
			span {
				font-size: 24rpx;
				color: $textDarkGray-color;
				margin-left: 10rpx;
				margin-top: 10rpx;
			}
		}
		.r {
			i {
				font-size: 28rpx;
				color: $textGray-color;
			}
		}
	}
	.house-num {
		display: flex;
		align-items: center;
		margin-left: 30rpx;
		padding-right: 30rpx;
		height: 88rpx;
		border-bottom: 2rpx solid $spLine-color;
		span {
			font-size: 28rpx;
			color: $textBlack-color;
			width: 160rpx;
		}
		input {
			flex: 1;
			font-size: 25rpx;
		}
	}
	.submit {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;

		span {
			display: inline-block;
			width: 88%;
			margin: auto;
			font-size: 28rpx;
			color: $textBlack-color;
			height: 76rpx;
			background-color: $theme-color;
			border-radius: 8rpx;
			text-align: center;
			line-height: 76rpx;
			margin-top: 20px;
		}
	}
	.submit1 {
		width: 100%;

		display: flex;
		align-items: center;
		justify-content: center;

		span {
			height: 76rpx;
			background-color: #fff;
			border-radius: 8rpx;
			border: 1px solid $theme-color;
			display: inline-block;
			width: 88%;
			margin: auto;
			font-size: 28rpx;
			color: $textBlack-color;
			text-align: center;
			line-height: 76rpx;
			margin-top: 20px;
		}
	}
}
</style>
